package com.logic.meeting.app.util;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import java.util.HashMap;

public class SoundPlayUtils {
    // SoundPool对象
    public static SoundPool mSoundPlayer = new SoundPool(10,
            AudioManager.STREAM_SYSTEM, 5);
    public static SoundPlayUtils soundPlayUtils;
    public static HashMap<Integer, Integer> mSPMap;
    // 上下文
    static Context mContext;

    /**
     * 初始化
     *
     * @param context
     */
    public static SoundPlayUtils init(Context context) {
        if (soundPlayUtils == null) {
            soundPlayUtils = new SoundPlayUtils();
        }

        // 初始化声音
        /**
         * 1：请扫会员码或刷卡登录
         * 2：请扫描会员码登录
         * 3：请输入店庆活动口令
         * 4：请出示核销码
         * 5：请出示核销码，或输入手机号与提币码
         * 6：请选择卡片数量后，提取游戏币
         * 7：正在出卡，出卡完成前请勿离开
         * 8：请将付款码对准扫码口
         * 9：请出示您的会员码
         */
        mContext = context;
        mSPMap = new HashMap<Integer, Integer>();
//        mSPMap.put(1, mSoundPlayer.load(mContext, R.raw.scan_qr_tips, 1));// 1)
//        mSPMap.put(2, mSoundPlayer.load(mContext, R.raw.scan_mem_code_login, 1));// 1)
//        mSPMap.put(3, mSoundPlayer.load(mContext, R.raw.store_activity_tips, 1));// 1)
//        mSPMap.put(4, mSoundPlayer.load(mContext, R.raw.show_code_tips, 1));// 1)
//        mSPMap.put(5, mSoundPlayer.load(mContext, R.raw.show_code_or_input_code_tips, 1));// 1)
//        mSPMap.put(6, mSoundPlayer.load(mContext, R.raw.please_check_card_and_out_coin, 1));// 1)
//        mSPMap.put(7, mSoundPlayer.load(mContext, R.raw.card_out_tips, 1));// 1)
//        mSPMap.put(8, mSoundPlayer.load(mContext, R.raw.please_show_pay_code, 1));// 1)
//        mSPMap.put(9, mSoundPlayer.load(mContext, R.raw.please_show_mem_code, 1));// 1)

        return soundPlayUtils;
    }

    /**
     * 播放声音
     *
     * @param soundID
     */
    public static int play(int soundID) {
        int lastId = mSoundPlayer.play(mSPMap.get(soundID), 1, 1, 0, 0, 1);
        return lastId;
    }


    /**
     * 释放音效资源
     */
    public static void release(int i) {
        mSoundPlayer.stop(i);
    }

}